import {BaseRender} from "../type/base-render";

/**
 * 基础渲染器类
 */
export abstract class BaseRenderer<Prop = any> {
    /**
     * 渲染方法 - 子类必须实现
     */
    abstract render(item: BaseRender<Prop>, propsData: any, emit: any): any;

    /**
     * 处理事件
     * @param events 事件配置
     */
    protected processEvents(events: any) {
        if (!events) return {};

        return Object.keys(events).reduce((acc: any, key: any) => {
            const vueFormatKey = key.replace(/^@/, ''); // 去掉可能存在的@前缀
            const eventName = `on${vueFormatKey[0].toUpperCase()}${vueFormatKey.slice(1)}`;
            acc[eventName] = events[key];
            return acc;
        }, {});
    }
}